package com.java.web;

import com.java.bean.Student;
import com.java.service.StudentService;
import com.java.service.impl.StudentServiceImpl;
import com.java.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: wjr
 * @Description:
 * @Date Created in  2020-09-07 2:04
 * @Modified By:
 */
@WebServlet(value = "/updateStudent")
public class UpdateStudentServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StudentService studentService = new StudentServiceImpl();
        ResponseUtils responseUtils = new ResponseUtils();
        //接收参数
        int studentId = Integer.parseInt(req.getParameter("studentId"));
        String studentNo = req.getParameter("studentNo");
        String stuName = req.getParameter("stuName");
        int stuAge = Integer.parseInt(req.getParameter("stuAge"));
        int gradeId = Integer.parseInt(req.getParameter("gradeId"));
        Student student = new Student(studentId, studentNo, stuName, stuAge, gradeId);
        String msg = "";
        if (studentService.updateStudent(student)){
            msg = "操作成功";
        }else {
            msg = "操作失败";
        }
        responseUtils.ResponseMsg(resp,msg,"/showAll");
    }
}
